using System.Collections.Generic;
using EPiServer.Core;

namespace EPiSugar.EntityAdapter
{
    public static class EntityExtensions
    {
        public static IEnumerable<T> Entities<T>(this IEnumerable<PageData> pages) where T:class 
        {
            EntityModel model = Current.Model;
            foreach(PageData page in pages)
            {
                T instance = model.GetEntity(page) as T;
                if(instance != null)
                    yield return instance;
            }
        }
        public static IList<T> ToEntityList<T>(this IList<PageData> pages) where T:class
        {
            return new List<T>(pages.Entities<T>());
        }
    }
}